<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
	
	/**
	 * 
	 * Initial view layout
	 */
	protected function _initView() {
		//initialize View
		$view = new Zend_View ();
		$view->doctype ( 'XHTML1_TRANSITIONAL' );
		$view->headTitle ( '' );
		$view->setEncoding('UTF-8');
		$view->skin = "default";
		
		//add view to viewRenderer
		$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper ( "ViewRenderer" );
		$viewRenderer->setView ( $view );
		return $view;
	
	}
	/**
	 * 
	 * Initail class  for application
	 */
	protected function _initAutoLoad(){
		//load model class and entites in application
		$applicationLoader = new Zend_Loader_Autoloader_Resource(
			array(
				"namespace"		=>	"",
				"basePath"		=>	APPLICATION_PATH,
				"resourceTypes" => array(
					"model" => array(
						"path" => "/models/", "namespace"=>"Model"
					),
					"entity" => array(
						"path" => "/models/entities/", "namespace" => "Entity"
					),
					"form" => array(
						"path" => "/forms/", "namespace" => "Form"
					)
				)
			
			)
		);

		//load all class in library
		$libraryLoader = new Zend_Loader_Autoloader_Resource(
			array(
				"namespace"		=>	"",
				"basePath"		=>	LIBRARY_PATH,
				"resourceTypes" => array(
					"Auth_Adapter" => array(
						"path" => "/Auth/Adapter/", "namespace"=>"Auth_Adapter"
					),
					"Constain" => array(
						"path" => "/Constain/", "namespace"=>"Constain"
					),
					"Helper" => array(
						"path" => "/Helper/", "namespace"=>"Helper"
					),
					"Plugin" => array(
						"path" => "/Plugin/", "namespace"=>"Plugin"
					)
				)
			
			)
		);
		
		//$resourceLoader->addResourceType("model", "models", "Model_");
	}
	
	
	/**
	 * 
	 * Initial Layout
	 */
	protected function _initLayout(){
		$layoutLoader = new Plugin_ChangeLayout();
		$frontController = Zend_Controller_Front::getInstance();
		$frontController->registerPlugin($layoutLoader);
	}
	
	/**
	 * 
	 * Initial Routes
	 * Add custom routes for website
	 */
	protected function _initRoutes(){
      try {
		$controller = Zend_Controller_Front::getInstance();
		$router = $controller->getRouter();
		$defaultRoute = new Zend_Controller_Router_Route_Static(
       							"",
       							array(
       								"module" => "front",
       								"controller" => "index",
       								"action"	=>	"index"
       							)
                );
        	$router->addRoute("default", $defaultRoute);

		$router->addRoute(
                  "category_view",
                  new Zend_Controller_Router_Route(
                        ':slug/:page',
                        array(
                              "module" => "front",
                              "controller" => "category",
                              "action"	=> "index",
                              "page" => "p1"
                        )
                  )
		);
		$router->addRoute(
                  "post_view",
                  new Zend_Controller_Router_Route_Regex(
                        '([a-z0-9-]+).html',
                        array(
                              "module" => "front",
                              "controller" => "post",
                              "action"	=> "index",
                        ),
                        array(
                            1 => 'slug'
                        ),
                        '%s.html'
                  )
		);
       	$router->addRoute(
                  "accessory_view",
                  new Zend_Controller_Router_Route(
                        'phu-tung/:cat_slug/:page',
                        array(
                              "module" => "front",
                              "controller" => "category",
                              "action"	=> "accessory",
                              "cat_slug" => "",
                              "page" => "p1"
                        )
                  )
		);
            $router->addRoute(
                  "box_view",
                  new Zend_Controller_Router_Route(
                        'thung-xe/:cat_slug/:page',
                        array(
                              "module" => "front",
                              "controller" => "category",
                              "action"	=> "box",
                              "cat_slug" => "",
                              "page" => "p1"
                        )
                  )
		);
            $router->addRoute(
                  "car_view",
                  new Zend_Controller_Router_Route(
                        'danh-muc-xe',
                        array(
                              "module" => "front",
                              "controller" => "category",
                              "action"	=> "car"
                        )
                  )
		);
            $router->addRoute(
                  "news_view",
                  new Zend_Controller_Router_Route(
                        'tin-tuc/:page',
                        array(
                              "module" => "front",
                              "controller" => "post",
                              "action"	=> "news",
                              "page" => "p1"
                        )
                  )
		);
            $router->addRoute(
                  "search",
                  new Zend_Controller_Router_Route(
                        'ket-qua-tim-kiem',
                        array(
                              "module" => "front",
                              "controller" => "category",
                              "action"	=> "search"
                        )
                  )
		);
       	//product route
       	//url ~/may-in-canon-lc200.html
        
            	
		//add admin dashboard
		//url = ~/admin
		$router->addRoute(
							'admin_dashboard', 							//route name
							new Zend_Controller_Router_Route_Static(
								'admin',								// route pattern
                                array(
                                	'module'		=> 'admin',			//module name
                                	'controller' 	=> 'dashboard',		//controller name
                                    'action' 		=> 'index'			//action name
                                )
                           )

						 );
						 
		//add admin login
		//url = ~/admin/login
		$router->addRoute(
							'admin_login', 								//route name
							new Zend_Controller_Router_Route_Static(
								'admin/login',								// route pattern
                                array(
                                	'module'		=> 'admin',			//module name
                                	'controller' 	=> 'user',			//controller name
                                    'action' 		=> 'login'
                                    
                               	)			//action name
                            )
						 );
		
		//add admin logout
		//url = ~/admin/logout
		$router->addRoute(
							'admin_logout', 							//route name
							new Zend_Controller_Router_Route(
								'admin/logout',							// route pattern
                                array(
                                	'module'		=> 'admin',			//module name
                                	'controller' 	=> 'user',			//controller name
                                    'action' 		=> 'logout')		//action name
                                )

						 );

		//add admin user list
		//url = ~/admin/user/list
		$router->addRoute(
							'admin_user_list', 								//route name
							new Zend_Controller_Router_Route(
								'admin/user/list',							// route pattern
                                array(
                                	'module'		=> 'admin',			//module name
                                	'controller' 	=> 'user',			//controller name
                                    'action' 		=> 'list')			//action name
                                )

						 );
						 
		//add admin user create route
		//url = ~/admin/user/create
		$router->addRoute(
							'admin_user_create', 								//route name
							new Zend_Controller_Router_Route(
								'admin/user/create',					// route pattern
                                array(
                                	'module'		=> 'admin',			//module name
                                	'controller' 	=> 'user',			//controller name
                                    'action' 		=> 'create')		//action name
                                )

						 );
		//url = ~/admin/user/edit
		$router->addRoute(
							'admin_user_edit', 								//route name
							new Zend_Controller_Router_Route(
								'admin/user/edit/:id',					// route pattern
                                array(
                                	'module'		=> 'admin',			//module name
                                	'controller' 	=> 'user',			//controller name
                                    'action' 		=> 'edit'
                                )		//action name
                            )

						 );
		//url = ~/admin/user/changepass
		$router->addRoute(
							'admin_user_changepass', 								//route name
							new Zend_Controller_Router_Route(
								'admin/user/changepass',					// route pattern
                                array(
                                	'module'		=> 'admin',			//module name
                                	'controller' 	=> 'user',			//controller name
                                    'action' 		=> 'changePass'
                                )		//action name
                            )

						 );
		//url = ~/admin/user/delete
		$router->addRoute(
							'admin_user_delete', 								//route name
							new Zend_Controller_Router_Route(
								'admin/user/delete/:id',					// route pattern
                                array(
                                	'module'		=> 'admin',			//module name
                                	'controller' 	=> 'user',			//controller name
                                    'action' 		=> 'delete',
                                	'id'			=> ''
                                )		//action name
                            )

						 );
		//url = ~/admin/category/:type/:id
		$router->addRoute(
			'admin_category',
			new Zend_Controller_Router_Route(
				'admin/category/:id/:action',
				array(
					'module'	=> 'admin',
					'controller' => 'category',
					'action' => 'index',
					'id' => ''
				)
			)
		);
		//url = ~/admin/category/delete/:type
		$router->addRoute(
			'admin_category_delete',
			new Zend_Controller_Router_Route(
				'admin/category/delete/:id/:type',
				array(
					'module'	=> 'admin',
					'controller' => 'category',
					'action' => 'delete',
					'type'	=> 'article',
					'id'	=>''
				)
			)
		);
		
		//url = ~/admin/article/create
		$router->addRoute(
			'admin_article_create',
			new Zend_Controller_Router_Route(
				'admin/article/create',
				array(
					'module'	=> 'admin',
					'controller' => 'article',
					'action' => 'create'
				)
			)
		);
		//url = ~/admin/article/edit/:id
		$router->addRoute(
			'admin_article_edit',
			new Zend_Controller_Router_Route(
				'admin/article/edit/:id',
				array(
					'module'	=> 'admin',
					'controller' => 'article',
					'action' => 'edit',
				)
			)
		);
		//url = ~/admin/article/list
		$router->addRoute(
			'admin_article_list',
			new Zend_Controller_Router_Route(
				'admin/article/list/:page',
				array(
					'module'	=> 'admin',
					'controller' => 'article',
					'action' => 'list',
					'page'	=> 1
				)
			)
		);
		//url = ~/admin/article/delete/:id
		$router->addRoute(
			'admin_article_delete',
			new Zend_Controller_Router_Route(
				'admin/article/delete/:id',
				array(
					'module'	=> 'admin',
					'controller' => 'article',
					'action' => 'delete',
					'id'	=> ''
				)
			)
		);
		//url = ~/admin/page/create
		$router->addRoute(
			'admin_page_create',
			new Zend_Controller_Router_Route(
				'admin/page/create',
				array(
					'module'	=> 'admin',
					'controller' => 'page',
					'action' => 'create'
				)
			)
		);
		//url = ~/admin/page/edit/:id
		$router->addRoute(
			'admin_page_edit',
			new Zend_Controller_Router_Route(
				'admin/page/edit/:id',
				array(
					'module'	=> 'admin',
					'controller' => 'page',
					'action' => 'edit',
				)
			)
		);
		//url = ~/admin/page/list
		$router->addRoute(
			'admin_page_list',
			new Zend_Controller_Router_Route(
				'admin/page/list/:page',
				array(
					'module'	=> 'admin',
					'controller' => 'page',
					'action' => 'list',
					'page'	=> 1
				)
			)
		);
		//url = ~/admin/page/delete/:id
		$router->addRoute(
			'admin_page_delete',
			new Zend_Controller_Router_Route(
				'admin/page/delete/:id',
				array(
					'module'	=> 'admin',
					'controller' => 'page',
					'action' => 'delete',
					'id'	=> ''
				)
			)
		);
		//url = ~/admin/supporter/list
		$router->addRoute(
			'admin_supporter_list',
			new Zend_Controller_Router_Route(
				'admin/supporter/list',
				array(
					'module'	 => 'admin',
					'controller' => 'supporter',
					'action'	 => 'list'
				)
			)
		);
		//url = ~/admin/supporter/create
		$router->addRoute(
			'admin_supporter_create',
			new Zend_Controller_Router_Route(
				'admin/supporter/create',
				array(
					'module'	 => 'admin',
					'controller' => 'supporter',
					'action'	 => 'create'
				)
			)
		);
		//url = ~/admin/supporter/edit
		$router->addRoute(
			'admin_supporter_edit',
			new Zend_Controller_Router_Route(
				'admin/supporter/edit/:id',
				array(
					'module'	 => 'admin',
					'controller' => 'supporter',
					'action'	 => 'edit',
					'id'		 =>''
				)
			)
		);
		//url = ~/admin/supporter/delete
		$router->addRoute(
			'admin_supporter_delete',
			new Zend_Controller_Router_Route(
				'admin/supporter/delete/:id',
				array(
					'module'	 => 'admin',
					'controller' => 'supporter',
					'action'	 => 'delete',
					'id'		 =>''
				)
			)
		);
		
		//url = ~/admin/product/list/page
		$router->addRoute(
			'admin_product_list',
			new Zend_Controller_Router_Route(
				'admin/product/list/:type/:page',
				array(
					'module'	 => 'admin',
					'controller' => 'product',
					'action'	 => 'list',
					'type'		=> 'car',
					'page'		 => 1
				)
			)
		);
		//url = ~/admin/product/create
		$router->addRoute(
			'admin_product_create',
			new Zend_Controller_Router_Route(
				'admin/product/create/:type',
				array(
					'module'	 => 'admin',
					'controller' => 'product',
					'action'	 => 'create',
					'type'		=> 'car'
				)
			)
		);
		//url = ~/admin/product/edit/:id
		$router->addRoute(
			'admin_product_edit',
			new Zend_Controller_Router_Route(
				'admin/product/edit/:type/:id',
				array(
					'module'	 => 'admin',
					'controller' => 'product',
					'action'	 => 'edit'
				)
			)
		);
		//url = ~/admin/product/delete/:id
		$router->addRoute(
			'admin_product_delete',
			new Zend_Controller_Router_Route(
				'admin/product/delete/:type/:id',
				array(
					'module'	 => 'admin',
					'controller' => 'product',
					'action'	 => 'delete',
					'type'		=> 'car',
					'id'		 => ''
				)
			)
		);
		//url = ~/admin/bill/list
		$router->addRoute(
			'admin_slide',
			new Zend_Controller_Router_Route(
				'admin/slide/:id',
				array(
					'module'	 => 'admin',
					'controller' => 'slide',
					'action'	 => 'index',
					'id'		 => ''
				)
			)
		);
		//url = ~/admin/bill/list
		$router->addRoute(
			'admin_slide_delete',
			new Zend_Controller_Router_Route(
				'admin/slide/delete/:id',
				array(
					'module'	 => 'admin',
					'controller' => 'slide',
					'action'	 => 'delete',
					'id'		=> ''
				)
			)
		);
		//url = ~/admin/bill/list
		$router->addRoute(
			'admin_bill_list',
			new Zend_Controller_Router_Route(
				'admin/bill/list',
				array(
					'module'	 => 'admin',
					'controller' => 'bill',
					'action'	 => 'list'
				)
			)
		);
		//url = ~/admin/bill/view
		$router->addRoute(
			'admin_bill_view',
			new Zend_Controller_Router_Route(
				'admin/bill/view/:id',
				array(
					'module'	 =>'admin',
					'controller' =>'bill',
					'action'	 =>'view',
					'id'  		 =>''
				)
			)
		);
		//url = ~/admin/bill/delete
		$router->addRoute(
			'admin_bill_delete',
			new Zend_Controller_Router_Route(
				'admin/bill/delete/:id',
				array(
					'module'	 =>'admin',
					'controller' =>'bill',
					'action'	 =>'delete',
					'id'  		 =>''
				)
			)
		);
		
		//url = ~/admin/banner
		$router->addRoute(
			'admin_banner',
			new Zend_Controller_Router_Route(
				'admin/banner/:id',
				array(
					'module'	 => 'admin',
					'controller' => 'banner',
					'action'	 => 'index',
					'id'		 => ''
				)
			)
		);
		$router->addRoute(
			'admin_banner_delete',
			new Zend_Controller_Router_Route(
				'admin/banner/delete/:id',
				array(
					'module'	 => 'admin',
					'controller' => 'banner',
					'action'	 => 'delete',
					'id'		 => ''
				)
			)
		);
		//url = ~/admin/menu
		$router->addRoute(
			'admin_menu',
			new Zend_Controller_Router_Route(
				'admin/menu/:id',
				array(
					'module'	 => 'admin',
					'controller' => 'menu',
					'action'	 => 'index',
					'id'		 => ''
				)
			)
		);
		//url = ~/admin/menu/delete
		$router->addRoute(
			'admin_menu_delete',
			new Zend_Controller_Router_Route(
				'admin/menu/delete/:id',
				array(
					'module'	 => 'admin',
					'controller' => 'menu',
					'action'	 => 'delete',
					'id'		 => ''
				)
			)
		);
		$router->addRoute(
			'admin_ajax_filters',
			new Zend_Controller_Router_Route(
				'admin/ajax/getfilters',
				array(
					'module'	 => 'admin',
					'controller' => 'ajax',
					'action'	 => 'getfilters'
				)
			)
		);
		$router->addRoute(
			'admin_ajax_pageslug',
			new Zend_Controller_Router_Route(
				'admin/ajax/pageslug',
				array(
					'module'	 => 'admin',
					'controller' => 'ajax',
					'action'	 => 'pageslug'
				)
			)
		);
		//route cho khuyen mai
		$router->addRoute(
			'admin_promotion',
			new Zend_Controller_Router_Route(
				'admin/promotion',
				array(
					'module'	=> 'admin',
					'controller'=> 'promotion',
					'action'	=> 'index'
				)
			)
		);
      }  catch (Exception $ex){
          echo $ex->getTraceAsString();
      }
	}
	
}